//
//  YMAddPhotoView.m
//  YMCommentDemo
//
//  Created by lantaiyuan on 2017/3/1.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "YMAddPhotoView.h"

@interface YMAddPhotoView ()
@property (nonatomic, strong) YMAddPhotoViewModel * viewModel;
@property (nonatomic, strong) UICollectionView * photoCollectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout * flowLayout;
@property (nonatomic, strong) HWImagePickerSheet *imgPickerActionSheet;
@end

@implementation YMAddPhotoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.photoCollectionView];
    }
    return self;
}

- (YMAddPhotoViewModel *)viewModel{
    if (!_viewModel) {
        _viewModel = [[YMAddPhotoViewModel alloc] init];
        [_viewModel initPickerView];
    }
    return _viewModel;
}

- (HWImagePickerSheet *)imgPickerActionSheet{
    if (!_imgPickerActionSheet) {
        _imgPickerActionSheet = [[HWImagePickerSheet alloc] init];
        _imgPickerActionSheet.delegate = self.viewModel;
    }
    return _imgPickerActionSheet;
}
- (UICollectionViewFlowLayout *)flowLayout{
    if (!_flowLayout) {
        _flowLayout = [[UICollectionViewFlowLayout alloc] init];
    }
    
    _flowLayout.minimumLineSpacing = 10;
    _flowLayout.minimumInteritemSpacing = 10;
    _flowLayout.itemSize = CGSizeMake(Photo_W, Photo_H);
    
    return _flowLayout;
}

- (UICollectionView *)photoCollectionView{
    if (!_photoCollectionView) {
        _photoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(15, 15, self.frame.size.width - 30, self.frame.size.height - 30) collectionViewLayout:self.flowLayout];
        _photoCollectionView.backgroundColor = [UIColor whiteColor];
        _photoCollectionView.dataSource = self.viewModel;
        _photoCollectionView.delegate = self.viewModel;
        self.viewModel.pickerCollectionView = _photoCollectionView;
        
        // Register nib file for the cell
        UINib *nib = [UINib nibWithNibName:@"HWCollectionViewCell" bundle: [NSBundle mainBundle]];
        [_photoCollectionView registerNib:nib forCellWithReuseIdentifier:@"HWCollectionViewCell"];
        
        self.viewModel.imgPickerActionSheet = self.imgPickerActionSheet;
    }
    return _photoCollectionView;
}

//获取选中的所有图片信息
- (NSArray*)getThumbnailImgArray{
    return [self.viewModel getSmallImageArray];
}
- (NSArray*)getBigImageArray{
    return [self getBigImageArray];
}
- (NSArray*)getALAssetArray{
    return [self getALAssetArray];
}
@end
